package com.jic.data.service.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import cn.hutool.core.date.DateUtil;
import com.jic.data.constant.consist.ResponseCode;
import com.jic.data.exception.AppRuntimeException;
import com.jic.data.model.vo.response.HistogramChartResponse;
import com.jic.data.model.vo.response.PieChartResponse;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import javax.annotation.Resource;
import java.math.BigDecimal;
import com.jic.data.model.vo.response.MonSingleOneMoreGuestSaleAmountResponse;
import com.jic.data.model.entity.MonSingleOneMoreGuestSaleAmount;
import com.jic.data.mapper.MonSingleOneMoreGuestSaleAmountMapper;
import com.jic.data.service.MonSingleOneMoreGuestSaleAmountService;

import lombok.extern.slf4j.Slf4j;
/**
 * 接口实现类
 *
 * @author : 建投数据科技(山东)有限公司
 * @version : v1.0.0
 * @email :
 * @since : 2020-03-09 10:12:20
 */
@Service
@Slf4j
public class MonSingleOneMoreGuestSaleAmountServiceImpl implements MonSingleOneMoreGuestSaleAmountService {

	@Resource
	private MonSingleOneMoreGuestSaleAmountMapper mapper;




	/**
	 * 不分页查询
	 *
	 * @param request 不分页查询入参实体类
	 * @return 数据库查到的实体类列表
	 */
	@Override
	public HistogramChartResponse listAllRecord(MonSingleOneMoreGuestSaleAmount request) {
		HistogramChartResponse response = new HistogramChartResponse();
		List<String> xDate = new ArrayList<>();
		List<Double> yOne = new ArrayList<>();
		List<Double> yMore = new ArrayList<>();


		List<MonSingleOneMoreGuestSaleAmount> list = mapper.selectBySelective(request);
		list.stream().forEach( category -> {
			xDate.add(DateUtil.format(category.getSaleDate(),"yyyy年MM"));
			yOne.add(category.getOneGuestQuantity().doubleValue() / 1000);
			yMore.add(category.getMoreGuestQuantity().doubleValue() / 1000);
		});
		response.setX(xDate);
		response.setY1(yOne);
		response.setY2(yMore);

		return response;
	}


	/**
	 * 一次客回购客销售额占比
	 * @param request
	 * @return
	 */
	@Override
	public List<PieChartResponse> selectOneMoreAmount(MonSingleOneMoreGuestSaleAmount request){


		MonSingleOneMoreGuestSaleAmount  amount =  mapper.selectOneMoreAmount(request);


		PieChartResponse responseOne = new PieChartResponse();
		responseOne.setName("一次客");
		responseOne.setValue(0.00);

		PieChartResponse responseMore = new PieChartResponse();
		responseMore.setName("回购客");
		responseMore.setValue(0.00);

		List<PieChartResponse> list = new ArrayList<>();

		if(null != amount){
			responseOne.setValue(amount.getOneGuestSaleAmount().doubleValue());
			responseMore.setValue(amount.getMoreGuestSaleAmount().doubleValue());
		}
		list.add(responseMore);
		list.add(responseOne);

		return list;
	}


}
